// pages/Memor/MemorD/MemorD.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    disapper:false,
    name:"",
    items:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this
    var preList = []
    that.setData({
      name: options.name
    })
    // console.log(options)
    console.log(that.data.name)
    // preList = get(that.data.name)
    preList = wx.getStorageSync(that.data.name)
    if(preList){
      that.setData({
        items:preList
      })
    }
  },

  onClick_icon:function(){
    var that = this
    if(that.data.disapper==false){
      that.setData({
        disapper:true
      })
    }
  },

  checkboxChange:function(e){
    var that = this
    var x = 0
    var y = 0
    // console.log(e)
    var l = e.detail.value
    console.log(l)
    var temp = that.data.items
    console.log(temp)
    for(y=0;y<l.length;y++){
      console.log(l[y])
      for(x=0;x<temp.length;x++){
        console.log(temp[x].value)
        console.log(l[y])
        if(temp[x].value == l[y]){
          console.log("find")
          temp[x].checked = true
          console.log(temp[x].checked)
        }
      }
    }
    console.log(temp)
    wx.setStorageSync(that.data.name, temp)
  },

  formSubmit:function(e){
    var that = this
    console.log(e.detail.value.memorbook)
    if(that.data.disapper==true){
      that.setData({
        disapper:false
      })
    }

    
    var data = {}
    var temp = that.data.items
    console.log(temp)
    data={
      value: e.detail.value.memorbook,
      checked: false
    }
    temp.push(data)
    console.log(temp)
    that.setData({
      items:temp
    })
    wx.setStorageSync(that.data.name, temp)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // 传递一个数据
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    var that = this
    var temp = that.data.items
    console.log(temp)
    wx.setStorageSync(that.data.name, temp)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})